﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace HZ.Web
{
    public class MessageBox
    {
        /// <summary>
        /// 提示消息并立即返回当前页面，不刷新
        /// </summary>
        /// <param name="page">this</param>
        /// <param name="msg">消息文本</param>
        /// <example>
        /// 代码示例
        /// <code>
        ///     HZ.Web.MessageBox.Show("测试消息");            
        ///     // 下面代码将无法执行
        ///     Response.Write("ABC");
        /// </code>
        /// 显示消息对话框，点击确定按钮之后，立即返回前一页，后面的代码将不再执行(如示例中Response.Write("ABC")将不执行)。
        /// </example>
        /// <remarks>
        ///     显示提示消息之后，立即返回前一页(不刷新)，后面代码不再执行。
        /// </remarks>
        public static void Show(string msg)
        {
            string js = string.Format("<script type=\"text/javascript\">alert('{0}');history.back();</script>", msg);
            HttpContext.Current.Response.Write(js);
            HttpContext.Current.Response.End();
        }

        [Obsolete("this method has Obsoleted. Use Show(string msg) instead")]
        public static void Show(System.Web.UI.Page page, string msg)
        {
            string js = string.Format("<script type=\"text/javascript\">alert('{0}');history.back();</script>", msg);
            HttpContext.Current.Response.Write(js);
            HttpContext.Current.Response.End();
        }
        public static void AlertAndRedirect(string sMessage, string sURL)
        {
            HttpContext.Current.Response.Write("<script>alert('" + sMessage + "');location.href='" + sURL + "'</script>");
        }
        public static void AlertAndRefresh(string sMessage)
        {
            HttpContext.Current.Response.Write("<script>alert('" + sMessage + "');location.href=location.href</script>");
        }
    }
}